//
//  YMJLayout.m
//  15网易云新闻条
//
//  Created by dllo on 16/8/3.
//  Copyright © 2016年 YMJ. All rights reserved.
//

#import "YMJLayout.h"

@interface YMJLayout ()
@property (nonatomic, strong) NSMutableArray *att_arr;
@property (nonatomic, assign) CGFloat att_height;
@property (nonatomic, assign) CGFloat WIDTH;
@end
@implementation YMJLayout
- (instancetype)init {
    if (self = [super init]) {
        _att_arr = [NSMutableArray array];
        _att_height = 44;
    }
    return self;
}
- (void)prepareLayout {
    [super prepareLayout];
    _WIDTH = 0;
    for (NSInteger i = 0; i < [self.collectionView numberOfItemsInSection:0]; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForItem:i inSection:0];
        UICollectionViewLayoutAttributes *att = [UICollectionViewLayoutAttributes layoutAttributesForCellWithIndexPath:indexPath];
        CGFloat width = [self.delegate collectionView:self.collectionView layout:self widthForItemAtIndexPath:indexPath height:_att_height];

        att.frame = CGRectMake(_WIDTH, 0, width, _att_height);
        [_att_arr addObject:att];
      
        _WIDTH = _WIDTH + width + 20;
    }

}
- (nullable NSArray<__kindof UICollectionViewLayoutAttributes *> *)layoutAttributesForElementsInRect:(CGRect)rect {
    return _att_arr;
}

- (CGSize)collectionViewContentSize {
    return CGSizeMake(_WIDTH, 44);
}
@end
